<!doctype html>
<html>
  <head>
    <title>Socket.IO Notification</title>
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      body { font: 13px Helvetica, Arial; }
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
      #messages { list-style-type: none; margin: 0; padding: 0; }
      #messages li { padding: 5px 10px; }
      #messages li:nth-child(odd) { background: #eee; }
    </style>
  </head>
  <body>
    <ul id="messages"></ul>
    <form action="">
      <input id="m" autocomplete="off" /><button>Send</button>
    </form>

    <script type="text/javascript" src="/socket.io/socket.io.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
    <script>

		let socket = io();
		$('form').submit(function(){
			socket.emit('notification', $('#m').val());
			$('#m').val('');
			return false;
		});
		socket.on('notification', function(msg){
			notice(msg);
		});

	    Notification.requestPermission(function(permission) {});
      
		function notice(msg) {
			let _notification = new Notification(`消息通知`,{
				body:`${msg}`,
				icon:'http://localhost:8080/23539868.jpg'
			});

			setTimeout(function(){
				_notification.close(); //设置5秒后自动关闭通知框
			},10000);
		  
		}
    </script>
  </body>
</html>